package com.xcity.record;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.xcity.merge.MergeUtil;

public class Invite extends BaseRecord {
	public static String SQL_PARA = "inviter, invitee, time";
	
	public static String COUNT_SQL = "select count(id) from invite {0}";
	public static String SELECT_LIMIT = "select * from invite {2} limit {0},{1}";
	public static String CONDITION = "WHERE invite.inviter not IN (SELECT player.id FROM player WHERE player.vipLvl = {0} AND player.`level` < {1} AND player.lastLoginTime < \"{2}\") AND invite.invitee not IN (SELECT player.id FROM player WHERE player.vipLvl = {0} AND player.`level` < {1} AND player.lastLoginTime < \"{2}\")";
	
//	protected long id;
	protected long inviter;
	protected long invitee;
	protected Date time;
	
	@Override
	public void load(ResultSet rs) throws SQLException {
//		this.id = rs.getLong(1);
		this.inviter = rs.getLong(2);
		this.invitee = rs.getLong(3);
		this.time = rs.getTimestamp(4);
	}

	@Override
	public String getColumnNames() {
		return SQL_PARA;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(MergeUtil.toSqlString(inviter));
		sb.append(", ");
		sb.append(MergeUtil.toSqlString(invitee));
		sb.append(", ");
		sb.append(MergeUtil.toDateString(time));
		return sb.toString();
	}
	
	@Override
	public String toSqlString(){
		switch (status) {
		case STATUS_INSERT:
		{
			StringBuffer sb = new StringBuffer();
			sb.append("INSERT INTO `");
			String tableName = getClass().getSimpleName().toLowerCase();
			sb.append(tableName);
			sb.append('`');
			sb.append(" (");
			sb.append(getColumnNames());
			sb.append(")");
			sb.append(" VALUES (");
			sb.append(toString());
			sb.append(");\n");
			return sb.toString();
		}
	}
	return "";
}

//	public long getId() {
//		return id;
//	}
//
//	public void setId(long id) {
//		this.id = id;
//	}

	public long getInviter() {
		return inviter;
	}

	public void setInviter(long inviter) {
		this.inviter = inviter;
	}

	public long getInvitee() {
		return invitee;
	}

	public void setInvitee(long invitee) {
		this.invitee = invitee;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}
}
